﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Spring.Context.Support;
using System.Web.Routing;
using Spring.Context;

namespace KMS.Web.Controllers
{
    public class ControllerFactory : DefaultControllerFactory
    {
        private static IApplicationContext SpringContext = ContextRegistry.GetContext();

        public override IController CreateController(RequestContext requestContext, string controllerName)
        {
            try
            {
                return (IController)SpringContext.GetObject(controllerName + "Controller");
            }
            catch (Exception)
            {
                throw new HttpException(404, "resource not found");
            }
        }

        public ControllerFactory() : base()
        {

        }
    }
}
